﻿#include "freditdialog.h"
#include "ui_freditdialog.h"
#include <QSqlQuery>
int editFileRDialog::ID;
editFileRDialog::editFileRDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::editFileRDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("修改信息状态：");
}

editFileRDialog::~editFileRDialog()
{
    delete ui;}

void editFileRDialog::receiveInfo(QStringList value){
    ID=value.at(0).toInt();
    ui->edtFromUnitB->setText(value.at(1));
    ui->edtToUnitB ->setText(value.at(2));
    ui->edtNameB->setText(value.at(3));
    QString temp = value.at(4);
    if(temp == QString("居民身份证")){
        ui->cbBxIDTypeB->setCurrentIndex(0);
    }else if(temp == QString("军官证")){
        ui->cbBxIDTypeB->setCurrentIndex(1);
    }else if(temp == QString("士官证")){
        ui->cbBxIDTypeB->setCurrentIndex(2);
    }else if(temp == QString("义务兵证")){
        ui->cbBxIDTypeB->setCurrentIndex(3);
    }else if(temp == QString("港澳台居民居住证")){
        ui->cbBxIDTypeB->setCurrentIndex(4);
    }else if(temp == QString("外籍人士在我国永久居住证")){
        ui->cbBxIDTypeB->setCurrentIndex(5);
    }else if(temp == QString("护照")){
        ui->cbBxIDTypeB->setCurrentIndex(6);
    }else if(temp == QString("其他")){
        ui->cbBxIDTypeB->setCurrentIndex(7);
    }

    ui->edtIDB->setText(value.at(5));
    if(value.at(6).trimmed() == "男"){
        ui->cmBxB->setCurrentIndex(0);
    }else{
        ui->cmBxB->setCurrentIndex(1);
    }
    ui->edtPlaceB->setText(value.at(7));
    ui->edtNowDutyB->setText(value.at(8));
    ui->edtDescriptionB->setText(value.at(9));
    ui->dtEdtFileB->setDate(QDate::fromString(value.at(10).trimmed(),"yyyy-MM-dd"));
    ui->dtEdtLbryB->setDate(QDate::fromString(value.at(11).trimmed(),"yyyy-MM-dd"));
}

void editFileRDialog::on_btnOkB_clicked()
{
    strFileFormUnit = ui->edtFromUnitB->text();//转档单位（人）
    strFileToUnit = ui->edtToUnitB->text();//接收人
    strFileName = ui->edtNameB->text();//姓名
    strIDType = ui->cbBxIDTypeB->currentText();//身份类型
    if(strIDType == QString("居民身份证")){
        strIDType = "1";
    }else if(strIDType == QString("军官证")){
        strIDType = "2";
    }else if(strIDType == QString("士官证")){
        strIDType = "3";
    }else if(strIDType == QString("义务兵证")){
        strIDType = "4";
    }else if(strIDType == QString("港澳台居民居住证")){
        strIDType = "5";
    }else if(strIDType == QString("外籍人士在我国永久居住证")){
        strIDType = "6";
    }else if(strIDType == QString("护照")){
        strIDType = "7";
    }else if(strIDType == QString("其他")){
        strIDType = "8";
    }
    strID = ui->edtIDB->text();//证件号码
    strFileSex = ui->cmBxB->currentText();//性别
    strFilePlace = ui->edtPlaceB->text();//籍贯
    strFileNowDuty = ui->edtNowDutyB->text();//现单位职务
    strFIleDescription = ui->edtDescriptionB->toPlainText();//备注
    strFileRDate = ui->dtEdtFileB->date().toString("yyyy-MM-dd");//接收时间
    strFileLbryDate = ui->dtEdtLbryB->date().toString("yyyy-MM-dd");//入库时间
    if(strFileFormUnit.trimmed().isEmpty()){//120
        ui->status->setText("修改信息状态：请输入转档单位（人）！");
    }else if(strFileFormUnit.size() > 120){
        ui->status->setText("修改信息状态：转档单位（人）信息字数超出！！");
    }else if(strFileToUnit.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入接收人！");
    }else if(strFileToUnit.size() > 50){//50
        ui->status->setText("修改信息状态：接收人信息字数超出！");
    }else if(strFileName.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入姓名！");
    }else if(strFileName.size() > 50){//50
        ui->status->setText("修改信息状态：姓名信息输入错误！");
    }else if(strID.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入证件号码！");
    }else if(strID.size() > 18 ){
        ui->status->setText("修改信息状态：请输入正确的证件号码！");
    }else if(strFilePlace.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入籍贯信息！");
    }else if(strFilePlace.trimmed().isEmpty()){//80
        ui->status->setText("修改信息状态：籍贯信息字数超出！");
    }else if(strFileNowDuty.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入现单位职务！");
    }else if(strFileNowDuty.size() > 80){//80
        ui->status->setText("修改信息状态：现单位职务信息字数超出！");
    }else if(strFIleDescription.size() > 500 ){//500
        ui->status->setText("修改信息状态：备注信息输入字数超出500字！");
    }else{
        QString strUpdate = QString("update FileReceive set FileFromUnit = '%1',FileToUnit = '%2',FilePerName = '%3',"
                                    "CredTypeID = '%4',IDNum = '%5',FilePerSex = '%6',FilePerPlace = '%7',"
                                    "FileNowDuty = '%8',FileRecRmk = '%9',FileRecTime = '%10',FileLbryTime = '%11' "
                                    "where FileRecID = '%12';")
                .arg(strFileFormUnit).arg(strFileToUnit).arg(strFileName).arg(strIDType).arg(strID).arg(strFileSex)
                .arg(strFilePlace).arg(strFileNowDuty).arg(strFIleDescription).arg(strFileRDate)
                .arg(strFileLbryDate).arg(ID);
        QSqlQuery query;
        if(query.exec(strUpdate)){
            ui->status->setText("修改信息状态：修改成功！");
            this->close();
        }else{
            ui->status->setText("修改信息状态：修改失败！");
        }
    }
}

void editFileRDialog::on_btnCancelB_clicked()
{
    this->close();
}
